package com.srs.action.agent;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONArray;

import com.srs.action.BaseAction;
import com.srs.dao.NiDataDao;
import com.srs.dao.QStatusDao;
import com.srs.dao.ServiceControlDao;
import com.srs.dao.agent.AgentDao;
import com.srs.dao.agent.ChangeServingCellDao;
import com.srs.dao.agent.LowCsrDao;
import com.srs.dao.agent.NoActivityDao;
import com.srs.dao.agent.NoCallGeneratedDao;
import com.srs.dao.agent.ParameterDao;
import com.srs.dao.agent.UseWeakRxDao;
import com.srs.dao.agent.UseWeakRxQualityDao;
import com.srs.dao.cfg.AreaDao;
import com.srs.dao.cfg.CountryDao;
import com.srs.dao.cfg.ProvinceDao;
import com.srs.dao.info.AgentPercentDao;
import com.srs.dao.info.CsrPercentDao;
import com.srs.dao.info.GrxPercentDao;
import com.srs.dao.info.GrxQualityPercentDao;
import com.srs.dao.info.RxDao;
import com.srs.dao.info.RxQualityDao;
import com.srs.model.NiData;
import com.srs.model.QStatus;
import com.srs.model.ServiceControl;
import com.srs.model.agent.Agent;
import com.srs.model.agent.Parameter;
import com.srs.model.cfg.Area;
import com.srs.model.cfg.Country;
import com.srs.model.cfg.Province;
import com.srs.model.info.AgentPercent;
import com.srs.model.info.CsrPercent;
import com.srs.model.info.GrxPercent;
import com.srs.model.info.GrxQualityPercent;
import com.srs.model.info.Rx;
import com.srs.model.info.RxQuality;
import com.srs.util.StringUtil;

/**
 * 
 * @author chienvh
 * 
 */
public class AgentAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private static final int TIME_OUT_FOR_UPDATE_QUERY = 5;
//	private static final int RECORD_PER_PAGE = 15;
	
	private Integer page;
	private Integer pageNum;	
	private Integer start;
	private Integer end;
	private Integer total;
	
	private String json;
	
	private Integer countryId=0;
	private Integer areaId=0;
	private Integer provinceId=0;
	private Integer cellId=0;
	
	private String onDate;
	private String fromDate;
	private String toDate;
	private AgentPercent agentPercent;
	private GrxPercent grxPercent;
	private GrxQualityPercent grxQualityPercent;
	private CsrPercent csrPercent;
	
	// Index form
	private Integer agentNoActivityNumber;
	private Integer agentNoCallGeneratedNumber;
	private Integer agentChangeServingCellNumber;
	private Integer agentUseWeakRxNumber;
	private Integer agentUseWeakRxQualityNumber;
	private Integer agentLowCsrNumber;
	
	// View add edit form
	private Agent agent;
	private List<Country> countries;
	private List<Area> areas;
	private List<Province> provinces;
	private List<Parameter> parameters; 
	
	// Alert type
	private String typeAlert;
	private List<Agent> agentAlerts;
	
	// List form
	private String msisdn;
	private String imei;
	private String customerId;
	private List<Agent> agents;
	
	// Param for update or query update agent
	private String updateId;

	// proprerty for chart
	private String data;
	private String toolTip;
	
	private List<AgentPercent> agentPercents;
	private List<GrxPercent> grxPercents;
	private List<GrxQualityPercent> grxQualityPercents;
	private List<CsrPercent> csrPercents;
	
	// Property for exam detail 
	private List<NiData> niDatas;
	/**
	 * Action agent/index - Agent information
	 * 
	 * @return
	 */
	public String index() {
		System.out.println("AgentAction::index");
		// Get filter Error
		Integer scopeId = 0 ;
		Integer scopeValueId =0 ;
		if (provinceId!=0){
			scopeId = 3;
			scopeValueId  = provinceId;
		} else if (areaId!=0){
			scopeId = 2;
			scopeValueId = areaId;
		} else if (countryId!=0){
			scopeId = 1;
			scopeValueId = countryId;
		}
		
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");		
		if (fromDate==null&&toDate==null){
			fromDate = dateFormat.format(new Date(new java.util.Date().getTime() - 8000*60*60*24));
			toDate = dateFormat.format(new Date(new java.util.Date().getTime() - 1000*60*60*24));
		}
		AgentPercentDao agentPercentDao = new AgentPercentDao();
		GrxPercentDao grxPercentDao = new GrxPercentDao();
		GrxQualityPercentDao grxQualityPercentDao = new GrxQualityPercentDao() ;
		CsrPercentDao csrPercentDao = new CsrPercentDao();
		AgentDao agentDao = new AgentDao();
		
		String agentList = agentDao.listForCondition(countryId, areaId, provinceId, cellId);
		
		// Data for chart		
		List<Date> dates = StringUtil.returnDatesBetweenDate(fromDate, toDate);
		String dataActivityChart = "var dataActivityChart = new Array(";
		String dataChangeServingCellChart = "var dataChangeServingCellChart = new Array(";
		String dataCallGeneratedMoreChart = "var dataCallGeneratedMoreChart = new Array(";
		String dataCallGeneratedChart = "var dataCallGeneratedChart = new Array(";
		String dataNewActiveChart = "var dataNewActiveChart = new Array(";
		String dataNewCallGeneratedChart = "var dataNewCallGeneratedChart = new Array(";
		String dataSamplesGoodChart = "var dataSamplesGoodChart = new Array(";
		String dataSamplesQualityGoodChart = "var dataSamplesQualityGoodChart = new Array(";
		String dataCallSucceedChart = "var dataCallSucceedChart = new Array(";
		boolean isFirstDate = true;
		Date 	beforeDate	= null;
		String strDate;
		toolTip ="";
		int count = 0;
		for (Date date : dates) {
			agentPercents 		= agentPercentDao.list(dateFormat.format(date), scopeId, scopeValueId);
			grxPercents 		= grxPercentDao.list(dateFormat.format(date), agentList);
			grxQualityPercents 	= grxQualityPercentDao.list(dateFormat.format(date), agentList);
			csrPercents			= csrPercentDao.list(dateFormat.format(date), agentList);
			
			if (isFirstDate){
				strDate = date.getDate() + "-" + (date.getMonth()+1);
				isFirstDate = false;
			} else {
				if (date.getMonth()!=beforeDate.getMonth()){
					strDate = date.getDate() + "-" + (date.getMonth()+1);
				} else {
					strDate = String.valueOf(date.getDate());
				}
			}
			beforeDate = date;

			if (agentPercents != null) {
				this.setAgentPercent();
				dataActivityChart = dataActivityChart + "['" + strDate +"', " + agentPercent.getPercentAgentsActivity() +"],";
				dataChangeServingCellChart = dataChangeServingCellChart + "['" + strDate +"', " + agentPercent.getPercentAgentsChangeServingCell() +"],";
				dataCallGeneratedMoreChart = dataCallGeneratedMoreChart + "['" + strDate +"', " + agentPercent.getPercentAgentsCallGeneratedMore() +"],";
				dataCallGeneratedChart = dataCallGeneratedChart + "['" + strDate +"', " + agentPercent.getPercentAgentsCallGenerated() +"],";
				dataNewActiveChart = dataNewActiveChart + "['" + strDate +"', " + agentPercent.getPercentAgentsNewActive() +"],";
				dataNewCallGeneratedChart = dataNewCallGeneratedChart + "['" + strDate +"', " + agentPercent.getPercentAgentsNewCallGeneratedStr() +"],";
				
				toolTip = toolTip + "activityChart.setTooltip([" + count + ", '"+ agentPercent.getPercentAgentsActivity() +"%']);";
				toolTip = toolTip + "changeServingCellChart.setTooltip([" + count + ", '"+ agentPercent.getPercentAgentsChangeServingCell() +"%']);";
				toolTip = toolTip + "callGeneratedMoreChart.setTooltip([" + count + ", '"+ agentPercent.getPercentAgentsCallGeneratedMore() +"%']);";
				toolTip = toolTip + "callGeneratedChart.setTooltip([" + count + ", '"+ agentPercent.getPercentAgentsCallGenerated() +"%']);";
				toolTip = toolTip + "newActiveChart.setTooltip([" + count + ", '"+ agentPercent.getPercentAgentsNewActive() +"%']);";
				toolTip = toolTip + "newCallGeneratedChart.setTooltip([" + count + ", '"+ agentPercent.getPercentAgentsNewCallGeneratedStr() +"%']);";
			}
			if (grxPercents!=null){
				this.setGrxPercent();
				dataSamplesGoodChart = dataSamplesGoodChart + "['" + strDate +"', " + this.getGrxPercent().getPercentSamplesGood() +"],";
				toolTip = toolTip + "samplesGoodChart.setTooltip([" + count + ", '"+ this.getGrxPercent().getPercentSamplesGood() +"%']);";

			}
			if (grxQualityPercents!=null){
				this.setGrxQualityPercent();
				dataSamplesQualityGoodChart = dataSamplesQualityGoodChart + "['" + strDate +"', " + this.getGrxQualityPercent().getPercentSamplesGood() +"],";
				toolTip = toolTip + "samplesQualityGoodChart.setTooltip([" + count + ", '"+ this.getGrxQualityPercent().getPercentSamplesGood() +"%']);";

			}
			if (csrPercents!=null){
				this.setCsrPercent();
				dataCallSucceedChart = dataCallSucceedChart + "['" + strDate +"', " + this.getCsrPercent().getPercentCallSucceeded() +"],";
				toolTip = toolTip + "callSucceedChart.setTooltip([" + count + ", '"+  this.getCsrPercent().getPercentCallSucceeded()  +"%']);";
				
			}
			count = count + 1;
		}		
		dataActivityChart = dataActivityChart.substring(0, dataActivityChart.length()-1) + ");";
		dataChangeServingCellChart = dataChangeServingCellChart.substring(0, dataChangeServingCellChart.length()-1) + ");";
		dataCallGeneratedMoreChart = dataCallGeneratedMoreChart.substring(0, dataCallGeneratedMoreChart.length()-1) + ");";
		dataCallGeneratedChart = dataCallGeneratedChart.substring(0, dataCallGeneratedChart.length()-1) + ");";
		dataNewActiveChart = dataNewActiveChart.substring(0, dataNewActiveChart.length()-1) + ");";
		dataNewCallGeneratedChart = dataNewCallGeneratedChart.substring(0, dataNewCallGeneratedChart.length()-1) + ");"; 
		dataSamplesGoodChart = dataSamplesGoodChart.substring(0, dataSamplesGoodChart.length()-1) + ");";
		dataSamplesQualityGoodChart = dataSamplesQualityGoodChart.substring(0, dataSamplesQualityGoodChart.length()-1) + ");";
		dataCallSucceedChart = dataCallSucceedChart.substring(0, dataCallSucceedChart.length()-1) + ");";		
		
		data = dataActivityChart + "\n" + 
			dataChangeServingCellChart +  "\n" + 
			dataCallGeneratedMoreChart +  "\n" + 
			dataCallGeneratedChart +  "\n" +
			dataNewActiveChart +  "\n" +
			dataNewCallGeneratedChart +  "\n" +
			dataSamplesGoodChart +  "\n" +
			dataSamplesQualityGoodChart +  "\n" +
			dataCallSucceedChart; 
		
		// Get AgentInfo
		System.out.println(agentList);
		agentPercents = agentPercentDao.list(toDate, scopeId, scopeValueId);
		grxPercents = grxPercentDao.list(toDate, agentList);
		grxQualityPercents = grxQualityPercentDao.list(toDate, agentList);
		csrPercents = csrPercentDao.list(toDate, agentList);
		if (agentPercents!=null){
			this.setAgentPercent();
		}		
		if (grxPercents!=null){
			this.setGrxPercent();
		}
		if (grxQualityPercents!=null){
			this.setGrxQualityPercent();
		}
		if (csrPercents!=null){
			this.setCsrPercent();
		}
		
		NoActivityDao noActivityDao = new NoActivityDao();
		NoCallGeneratedDao noCallGeneratedDao = new NoCallGeneratedDao();
		ChangeServingCellDao changeServingCellDao = new ChangeServingCellDao();
		UseWeakRxDao useWeakRxDao = new UseWeakRxDao();
		UseWeakRxQualityDao useWeakRxQualityDao = new UseWeakRxQualityDao();
		LowCsrDao lowCsrDao = new LowCsrDao();
		this.setAgentNoActivityNumber(noActivityDao.count(toDate, agentList).intValue());
		this.setAgentNoCallGeneratedNumber(noCallGeneratedDao.count(toDate, agentList).intValue());
		this.setAgentChangeServingCellNumber(changeServingCellDao.count(toDate, agentList).intValue());
		this.setAgentUseWeakRxNumber(useWeakRxDao.count(toDate, agentList).intValue());
		this.setAgentUseWeakRxQualityNumber(useWeakRxQualityDao.count(toDate, agentList).intValue());
		this.setAgentLowCsrNumber(lowCsrDao.count(toDate).intValue());
		
		return SUCCESS;
	}

	
	/**
	 * Action agent/list - Agent management
	 * 
	 * @return
	 */
	public String list() {
		System.out.println("AgentAction::list");
		AgentDao agentDao = new AgentDao();
		agents = agentDao.list(countryId, areaId, provinceId, cellId, msisdn, customerId, imei);
		if (page==null || (page-1)*RECORD_PER_PAGE>agents.size()){
			page = 1;
		}
		if (agents.size()%RECORD_PER_PAGE==0){
			pageNum = agents.size()/RECORD_PER_PAGE;
		} else {
			pageNum = agents.size()/RECORD_PER_PAGE + 1;
		}
		
		start = (page-1)*RECORD_PER_PAGE + 1;
		total = agents.size();
		if (total<(page)*RECORD_PER_PAGE){
			end = total;
		} else {
			end = (page)*RECORD_PER_PAGE;
		}
		List<Agent> pageAgents = new ArrayList<Agent>() ;
		for(int i=0; i<agents.size(); i++){
			if (i>=(page-1)*RECORD_PER_PAGE && i<(page)*RECORD_PER_PAGE){
				agents.get(i).setIndex(i+1);
				pageAgents.add(agents.get(i));
			}
		}
		agents = pageAgents;
		return SUCCESS;
	}

	/**
	 * 	
	 * @return
	 */	
	public String view(){
		AgentDao agentDao = new AgentDao();
		agent = agentDao.get(agent.getAgentId());
		
		CountryDao 		countryDao	= new CountryDao();
		AreaDao			areaDao 	= new AreaDao();
		ProvinceDao 	provinceDao = new ProvinceDao();
		ParameterDao 	parameterDao= new ParameterDao();		
		try{
			agent.setCountryName(countryDao.get(agent.getCountryId()).getCountryName());
		} catch (Exception e) {
			agent.setCountryName("Không xác định");
		}
		try{
			agent.setAreaName(areaDao.get(agent.getAreaId()).getAreaName());
		} catch (Exception e) {
			agent.setAreaName("Không xác định");
		}
		try{
			agent.setProvinceName(provinceDao.get(agent.getProvinceId()).getProvinceName());
		} catch (Exception e) {
			agent.setProvinceName("Không xác định");
		}
		try{
			agent.setAgentParameterName(parameterDao.get(agent.getAgentParameterId()).getAgentParameterName());
		} catch (Exception e) {
			agent.setAgentParameterName("Không xác định");
		}		
		return SUCCESS;
	}
	
	public String detail() throws ParseException{
		AgentDao agentDao = new AgentDao();
		agent = agentDao.get(agent.getAgentId());
		
		RxDao rxDao = new RxDao();
		RxQualityDao rxQualityDao = new RxQualityDao();
		
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");		
		if (fromDate==null&&toDate==null){
			fromDate = dateFormat.format(new Date(new java.util.Date().getTime() - 8000*60*60*24));
			toDate = dateFormat.format(new Date(new java.util.Date().getTime() - 1000*60*60*24));
		}
//		fromDate = "2009-10-13";
//		toDate = "2009-10-27";
		// Data for chart
		Date fDate = dateFormat.parse(fromDate);
		Date tDate = dateFormat.parse(toDate);
		int count = new Double((tDate.getTime() - fDate.getTime())/(1000*60*60*24)).intValue();
		
		// Rx chart data
		String dataRxChart = "var dataRxChart = new Array(";
		String dataRxChartMin = "rxChart.setDataArray(["; 
		String dataRxChartAverage = "rxChart.setDataArray([";
		String dataRxChartMax = "rxChart.setDataArray([";
		
		boolean isFirstDate = true;
		Date 	beforeDate	= null;
		String strDate;		
		toolTip = "";
		
		for(int index=0; index<=count; index++){

			Date curDate = new Date(fDate.getTime()+index*1000*60*60*24);
			
			if (isFirstDate){
				strDate = curDate.getDate() + "-" + (curDate.getMonth() + 1);
				isFirstDate = false;
			} else {
				if (curDate.getMonth()!=beforeDate.getMonth()){
					strDate = curDate.getDate() + "-" + (curDate.getMonth() + 1);
				} else {
					strDate = String.valueOf(curDate.getDate());
				}
			}
			beforeDate = curDate;
			
			Rx rx = rxDao.get(agent.getAgentId(), dateFormat.format(curDate));
			if (rx==null){
				dataRxChartMin = dataRxChartMin + "['" + strDate + "', 0],";
				dataRxChartAverage = dataRxChartAverage + "['" + strDate + "', 0],";
				dataRxChartMax = dataRxChartMax + "['" + strDate + "', 0],";
				dataRxChart = dataRxChart + "['" + strDate + "', 0],";
				toolTip = toolTip + "rxChart.setTooltip([" + index + ", '"+  0  +" - Cường độ sóng nhỏ nhất', 'min']);";
				toolTip = toolTip + "rxChart.setTooltip([" + index + ", '"+  0  +" - Cường độ sóng trung bình', 'average']);";
				toolTip = toolTip + "rxChart.setTooltip([" + index + ", '"+  0  +" - Cường độ sóng lớn nhất', 'max']);";				
			} else {
				System.out.println(rx.getAgentId() + ":::" + rx.getOnDate() + ":::" + rx.getRxAverage());
				dataRxChartMin = dataRxChartMin + "['" + strDate + "', " + rx.getRxMin() + "],";
				dataRxChartAverage = dataRxChartAverage + "['" + strDate + "', " + rx.getRxAverage() + "],";
				dataRxChartMax = dataRxChartMax + "['" + strDate + "', " + rx.getRxMax() + "],";
				dataRxChart = dataRxChart + "['" + strDate + "', " + rx.getRxAverage() +"],";
				toolTip = toolTip + "rxChart.setTooltip([" + index + ", '"+  rx.getRxMin()  +" - Cường độ sóng nhỏ nhất', 'min']);";
				toolTip = toolTip + "rxChart.setTooltip([" + index + ", '"+  rx.getRxAverage()  +" - Cường độ sóng trung bình', 'average']);";
				toolTip = toolTip + "rxChart.setTooltip([" + index + ", '"+  rx.getRxMax()  +" - Cường độ sóng lớn nhất', 'max']);";
			}
		}
		dataRxChartMin = dataRxChartMin.substring(0, dataRxChartMin.length()-1) + "], 'min');";
		dataRxChartAverage = dataRxChartAverage.substring(0, dataRxChartAverage.length()-1) + "], 'average');";
		dataRxChartMax = dataRxChartMax.substring(0, dataRxChartMax.length()-1) + "], 'max');";		
		dataRxChart = dataRxChart.substring(0, dataRxChart.length()-1) + ");";

		
		// RxQuality chart data
		String dataRxQualityChart = "var dataRxQualityChart = new Array(";
		String dataRxQualityChartMin = "rxQualityChart.setDataArray(["; 
		String dataRxQualityChartAverage = "rxQualityChart.setDataArray([";
		String dataRxQualityChartMax = "rxQualityChart.setDataArray([";
		
		isFirstDate = true;
		beforeDate	= null;
		for(int index=0; index<=count; index++){
			
			Date curDate = new Date(fDate.getTime()+index*1000*60*60*24);
			
			if (isFirstDate){
				strDate = curDate.getDate() + "-" + (curDate.getMonth() + 1);
				isFirstDate = false;
			} else {
				if (curDate.getMonth()!=beforeDate.getMonth()){
					strDate = curDate.getDate() + "-" + (curDate.getMonth() + 1);
				} else {
					strDate = String.valueOf(curDate.getDate());
				}
			}
			beforeDate = curDate;			
			
//			Date curDate = new Date(fDate.getTime()+index*1000*60*60*24);
			RxQuality rxQuality = rxQualityDao.get(agent.getAgentId(), dateFormat.format(curDate));
			if (rxQuality==null){
				dataRxQualityChartMin = dataRxQualityChartMin  + "['" + strDate + "', 0],";
				dataRxQualityChartAverage = dataRxQualityChartAverage + "['" + strDate + "', 0],";
				dataRxQualityChartMax = dataRxQualityChartMax + "['" + strDate + "', 0],";
				dataRxQualityChart = dataRxQualityChart + "['" + strDate + "', 0],";
				toolTip = toolTip + "rxQualityChart.setTooltip([" + index + ", '"+  0  +" - Chất lượng sóng kém nhất', 'min']);";
				toolTip = toolTip + "rxQualityChart.setTooltip([" + index + ", '"+  0  +" - Chất lượng sóng trung bình', 'average']);";
				toolTip = toolTip + "rxQualityChart.setTooltip([" + index + ", '"+  0  +" - Chất lượng sóng tốt nhất', 'max']);";				
			} else {
				System.out.println(rxQuality.getAgentId() + ":::" + rxQuality.getOnDate() + ":::" + rxQuality.getRxQualityAverage());
				dataRxQualityChartMin = dataRxQualityChartMin + "['" + strDate + "', " + rxQuality.getRxQualityMin() +"],";
				dataRxQualityChartAverage = dataRxQualityChartAverage + "['" + strDate + "', " + rxQuality.getRxQualityAverage() +"],";
				dataRxQualityChartMax = dataRxQualityChartMax + "['" + strDate + "', " + rxQuality.getRxQualityMax() +"],";				
				dataRxQualityChart = dataRxQualityChart + "['" + strDate + "', " + rxQuality.getRxQualityAverage() +"],";
				toolTip = toolTip + "rxQualityChart.setTooltip([" + index + ", '"+  rxQuality.getRxQualityMin()  +" - Chất lượng sóng kém nhất', 'min']);";
				toolTip = toolTip + "rxQualityChart.setTooltip([" + index + ", '"+  rxQuality.getRxQualityAverage()  +" - Chất lượng sóng trung bình', 'average']);";
				toolTip = toolTip + "rxQualityChart.setTooltip([" + index + ", '"+ rxQuality.getRxQualityMax()  +" - Chất lượng sóng tốt nhất', 'max']);";				
			}
		}
		dataRxQualityChartMin = dataRxQualityChartMin.substring(0, dataRxQualityChartMin.length()-1) + "], 'min');";
		dataRxQualityChartAverage = dataRxQualityChartAverage.substring(0, dataRxQualityChartAverage.length()-1) + "], 'average');";
		dataRxQualityChartMax = dataRxQualityChartMax.substring(0, dataRxQualityChartMax.length()-1) + "], 'max');";
		dataRxQualityChart = dataRxQualityChart.substring(0, dataRxQualityChart.length()-1) + ");";
		
		data = "\n" + 
						dataRxChartMin + "\n" +
						dataRxChartAverage + "\n" +
						dataRxChartMax + "\n" +
						dataRxQualityChartMin + "\n" +
						dataRxQualityChartAverage + "\n" +
						dataRxQualityChartMax;
		return SUCCESS;
	}	
	
	public String detailExam() {
		NiDataDao niDataDao = new NiDataDao();
		this.setNiDatas(niDataDao.list(agent.getMsisdn()));
		this.setTotal(this.niDatas.size());
		
		if (page==null  || (page-1)*RECORD_PER_PAGE>this.niDatas.size()){
			page = 1;
		}
		if (niDatas.size()%RECORD_PER_PAGE==0){
			pageNum = niDatas.size()/RECORD_PER_PAGE;
		} else {
			pageNum = niDatas.size()/RECORD_PER_PAGE + 1;
		}
		
		start = (page-1)*RECORD_PER_PAGE + 1;
		total = niDatas.size();
		if (total<(page)*RECORD_PER_PAGE){
			end = total;
		} else {
			end = (page)*RECORD_PER_PAGE;
		}
		List<NiData> pageNiDatas = new ArrayList<NiData>() ;
		for(int i=0; i<niDatas.size(); i++){
			if (i>=(page-1)*RECORD_PER_PAGE && i<(page)*RECORD_PER_PAGE){
				niDatas.get(i).setIndex(i+1);
				pageNiDatas.add(niDatas.get(i));
			}
		}
		niDatas = pageNiDatas;
		
		
		return SUCCESS;
	}
	/**
	 * 	
	 * @return
	 */
	public String add(){
		CountryDao 		countryDao	= new CountryDao();
		AreaDao			areaDao 	= new AreaDao();
		ProvinceDao 	provinceDao = new ProvinceDao();
		ParameterDao 	parameterDao= new ParameterDao();
		setCountries(countryDao.list());
		setAreas(areaDao.list());
		setProvinces(provinceDao.list());
		setParameters(parameterDao.list());
		return SUCCESS;
	}
	
	/**
	 * 
	 * @return
	 */
	public String addComplete(){
		AgentDao agentDao = new AgentDao();
		agent.setAgentStatus("IDLE");
		agentDao.insert(agent);		
		return SUCCESS;
	}	
	/**
	 * 	
	 * @return
	 */
	public String edit(){
		CountryDao 		countryDao	= new CountryDao();
		AreaDao			areaDao 	= new AreaDao();
		ProvinceDao 	provinceDao = new ProvinceDao();
		ParameterDao 	parameterDao= new ParameterDao();
		setCountries(countryDao.list());
		setAreas(areaDao.list());
		setProvinces(provinceDao.list());
		setParameters(parameterDao.list());
		
		AgentDao agentDao = new AgentDao();
		agent = agentDao.get(agent.getAgentId());		
		return SUCCESS;
	}
	
	/**
	 * 
	 * @return
	 */
	public String editComplete(){
		AgentDao agentDao = new AgentDao();
		agentDao.update(agent);		
		return SUCCESS;
	}
	
	/**
	 * 
	 */
	public String deleteComplete(){
		AgentDao agentDao = new AgentDao();
		agentDao.delete(agent.getAgentId());
		return SUCCESS;
	}
	
	/**
	 * Action agent/alert - Agent alert
	 * 
	 * @return
	 */
	public String alert() {
		System.out.println("AgentAction::alert");
		AgentDao agentDao = new AgentDao();
		List<Integer> agentIds = new ArrayList<Integer>();
		if (typeAlert==null) typeAlert = "";
		if (typeAlert.equalsIgnoreCase("noActivity")){
			NoActivityDao noActivityDao = new NoActivityDao();
			agentIds.addAll(noActivityDao.listAgentIds());

		} else if (typeAlert.equalsIgnoreCase("noCallGenerated")) {
			
			NoCallGeneratedDao noCallGeneratedDao = new NoCallGeneratedDao();
			agentIds.addAll(noCallGeneratedDao.listAgentIds());

		} else if (typeAlert.equalsIgnoreCase("changeServingCell")) {
			ChangeServingCellDao changeServingCellDao = new ChangeServingCellDao();
			agentIds.addAll(changeServingCellDao.listAgentIds());

		} else if (typeAlert.equalsIgnoreCase("useWeakRx")) {
			UseWeakRxDao useWeakRxDao = new UseWeakRxDao();
			agentIds.addAll(useWeakRxDao.listAgentIds());

		} else if (typeAlert.equalsIgnoreCase("useWeakRxQuality")) {
			UseWeakRxQualityDao useWeakRxQualityDao = new UseWeakRxQualityDao();
			agentIds.addAll(useWeakRxQualityDao.listAgentIds());
			
		} else if (typeAlert.equalsIgnoreCase("lowCsr")) {
			LowCsrDao lowCsrDao = new LowCsrDao();
			agentIds.addAll(lowCsrDao.listAgentIds());

		} else{
			NoActivityDao noActivityDao = new NoActivityDao();
			NoCallGeneratedDao noCallGeneratedDao = new NoCallGeneratedDao();
			ChangeServingCellDao changeServingCellDao = new ChangeServingCellDao();
			UseWeakRxDao useWeakRxDao = new UseWeakRxDao();
			UseWeakRxQualityDao useWeakRxQualityDao = new UseWeakRxQualityDao();
			LowCsrDao lowCsrDao = new LowCsrDao();
			agentIds.addAll(noActivityDao.listAgentIds());
			agentIds.addAll(noCallGeneratedDao.listAgentIds());
			agentIds.addAll(changeServingCellDao.listAgentIds());
			agentIds.addAll(useWeakRxDao.listAgentIds());
			agentIds.addAll(useWeakRxQualityDao.listAgentIds());
			agentIds.addAll(lowCsrDao.listAgentIds());
			
		}
		this.setAgentAlerts(agentDao.listAlert(agentIds, agentDao.listForCondition(countryId, areaId, provinceId, cellId)));
		
		// Paging
		if (page==null  || (page-1)*RECORD_PER_PAGE>agentAlerts.size()){
			page = 1;
		}
		if (agentAlerts.size()%RECORD_PER_PAGE==0){
			pageNum = agentAlerts.size()/RECORD_PER_PAGE;
		} else {
			pageNum = agentAlerts.size()/RECORD_PER_PAGE + 1;
		}
		
		if (pageNum<page) page = pageNum;
		
		start = (page-1)*RECORD_PER_PAGE + 1;
		total = agentAlerts.size();
		if (total<(page)*RECORD_PER_PAGE){
			end = total;
		} else {
			end = (page)*RECORD_PER_PAGE;
		}
		List<Agent> pageAgents = new ArrayList<Agent>() ;
		for(int i=0; i<agentAlerts.size(); i++){
			if (i>=(page-1)*RECORD_PER_PAGE && i<(page)*RECORD_PER_PAGE){
				agentAlerts.get(i).setIndex(i+1);
				pageAgents.add(agentAlerts.get(i));
			}
		}
		
		setAgentAlerts(pageAgents);
		
		return SUCCESS;
	}	
	
	public String cellList() {
		System.out.println("AgentAction::cellList");

		// Init Dao
		CountryDao countryDao = new CountryDao();
		AreaDao areaDao = new AreaDao();
		ProvinceDao provinceDao = new ProvinceDao();
		AgentDao agentDao = new AgentDao();
		
		// Choose contry
		if (countryId!=null && countryId!=0){
			List<Area> areas = areaDao.list(countryId);
			setJson("{areas: " + JSONArray.fromObject(areas) + "}");
			return SUCCESS;	
		}
		
		// Choose area
		if (areaId!=null && areaId!=0){
			List<Province> provinces = provinceDao.list(areaId);
			setJson("{provinces: " + JSONArray.fromObject(provinces) + "}");
			return SUCCESS;	
		}
		
		// Choose province
		if (provinceId!=null && provinceId!=0){
			List<Agent> agents = agentDao.listAgentForCellId(provinceId);
			setJson("{agents: " + JSONArray.fromObject(agents) + "}");
			return SUCCESS;	
		}
				
		
		// Get list
		List<Country> countries = countryDao.list();
		List<Area> areas = areaDao.list();
		List<Province> provinces = provinceDao.list();
		List<Agent> agents = agentDao.listAgentForCellId();
		
		// Put to json;
		setJson("{countries: " +
				JSONArray.fromObject(countries).toString() +
				", areas: " + 
				JSONArray.fromObject(areas).toString()  +
				", provinces:" +
				JSONArray.fromObject(provinces).toString() +
				", agents:" +
				JSONArray.fromObject(agents).toString() +
				"}");
		return SUCCESS;
	}

	public String updateAgent() {
		ServiceControlDao serviceControlDao = new ServiceControlDao();
		ServiceControl serviceControl = new ServiceControl();
		serviceControl.setAgentId(agent.getAgentId());
		serviceControl.setServiceStatus("NP");		
		if (updateId.equalsIgnoreCase("update_cfg")) {
			serviceControl.setServiceRequest("ACTIVATE");
		} else if (updateId.equalsIgnoreCase("activate")) {
			serviceControl.setServiceRequest("ACTIVATE");
		} else if (updateId.equalsIgnoreCase("deactivate")) {
			serviceControl.setServiceRequest("DEACTIVATE");
		} else if (updateId.equalsIgnoreCase("reset")) {
			serviceControl.setServiceRequest("RESET");
		}
		setJson("Bạn đã thực hiện thành công!");
		serviceControlDao.insert(serviceControl);
		
		return SUCCESS;
	}


	public String updateAgentQuery() {
		int timeOut = 30;
		
		AgentDao agentDao = new AgentDao();
		
		ServiceControlDao serviceControlDao = new ServiceControlDao();
		ServiceControl serviceControl = new ServiceControl();
		serviceControl.setAgentId(agent.getAgentId());
		serviceControl.setServiceStatus("NP");
		if (updateId.equalsIgnoreCase("query_config")) {
			serviceControl.setServiceRequest("QUERY_CONFIGURATION");
			serviceControlDao.insert(serviceControl);
			Date startDate = new Date();

			agent = agentDao.get(agent.getAgentId()) ;
			
			while (startDate.getTime() + TIME_OUT_FOR_UPDATE_QUERY*1000 > new Date().getTime()){
				QStatusDao qStatusDao = new QStatusDao();
				QStatus qStatus = qStatusDao.getNewest(agent.getMsisdn());
				if (qStatus!=null){
					System.out.println("QUERY_CONFIGURATION");
					if (new Date(qStatus.getInsertedTime()).after(new Date(serviceControl.getInsertedDtime()))){
						serviceControl.setServiceRequest("SENT");
						setJson("Bạn đã thực hiện thành công!");
						return SUCCESS;
					}
				}
			}
			serviceControl.setServiceRequest("FAIL");
			
		} else if (updateId.equalsIgnoreCase("query_status")) {
			serviceControl.setServiceRequest("QUERY_STATUS");
			serviceControlDao.insert(serviceControl);

			Date startDate = new Date();

			agent = agentDao.get(agent.getAgentId()) ;
			
			while (startDate.getTime() + TIME_OUT_FOR_UPDATE_QUERY*1000 > new Date().getTime()){
				QStatusDao qStatusDao = new QStatusDao();
				QStatus qStatus = qStatusDao.getNewest(agent.getMsisdn());
				if (qStatus!=null){
					System.out.println("QUERY_STATUS");
					if (new Date(qStatus.getInsertedTime()).after(new Date(serviceControl.getInsertedDtime()))){
						serviceControl.setServiceRequest("SENT");
						setJson("Bạn đã thực hiện thành công!");
						return SUCCESS;
					}
				}
			}
			serviceControl.setServiceRequest("FAIL");
			
		} else if (updateId.equalsIgnoreCase("measure")) {
			serviceControl.setServiceRequest("MEASURE");
			serviceControlDao.insert(serviceControl);
			Date startDate = new Date();
			
			agent = agentDao.get(agent.getAgentId()) ;
			
			while (startDate.getTime() + TIME_OUT_FOR_UPDATE_QUERY*1000 > new Date().getTime()){
				NiDataDao niDataDao =  new NiDataDao();
				NiData niData = niDataDao.getNewest(agent.getMsisdn());
				
				if (niData!=null){
					System.out.println("MEASURE");
					if (new Date(niData.getInsertedTime()).after(new Date(serviceControl.getInsertedDtime()))){
						serviceControl.setServiceRequest("SENT");
						setJson("Bạn đã thực hiện thành công!");
						return SUCCESS;
					}
				}
			}
			serviceControl.setServiceRequest("FAIL");

		}
		
		setJson("Thao tác không thực hiện được!");
		return SUCCESS;
	}
	
	/**
	 * Action group/listJson - Role management
	 * 
	 */
	public String nameIsUsed() {
		System.out.println("RoleAction::listJson");

		// Init Dao
		AgentDao agentDao = new AgentDao();
		
		// Put to json;
		setJson("{nameIsUsed: " +
				JSONArray.fromObject(agentDao.nameIsUsed(agent.getMsisdn())).toString() +
				"}");
		return SUCCESS;
	}		
	/****************************************************************************************
	 *  Set or get function
	 ****************************************************************************************/
			
	
	/**
	 * @param agentPercent the agentPercent to set
	 */
	public void setAgentPercent() {
		agentPercent = new AgentPercent();
		Long percentAgentsActivity = new Long(0);
		Long percentAgentsCallGenerated = new Long(0);
		Long percentAgentsCallGeneratedMore = new Long(0);
		Long percentAgentsChangeServingCell = new Long(0);
		Long percentAgentsNewActive = new Long(0);
		Long percentAgentsNewCallGenerated = new Long(0);
		Long percentAgentsTotal = new Long(0);
		for (AgentPercent item : agentPercents) {
			percentAgentsActivity = percentAgentsActivity
					+ item.getNbAgentsActivity();
			percentAgentsCallGenerated = percentAgentsCallGenerated
					+ item.getNbAgentsCallGenerated();
			percentAgentsCallGeneratedMore = percentAgentsCallGeneratedMore
					+ item.getNbAgentsCallGeneratedMore();
			percentAgentsChangeServingCell = percentAgentsChangeServingCell
					+ item.getNbAgentsChangeServingCell();
			percentAgentsNewActive = percentAgentsNewActive
					+ item.getNbAgentsNewActive();
			percentAgentsNewCallGenerated = percentAgentsNewCallGenerated
					+ item.getNbAgentsNewCallGenerated();
			percentAgentsTotal = percentAgentsTotal
					+ item.getNbAgentsTotal();
		}

		if (percentAgentsTotal==0){
			agentPercent.setPercentAgentsActivity(new Double(0));
			agentPercent.setPercentAgentsCallGenerated(new Double(0));
			agentPercent.setPercentAgentsCallGeneratedMore(new Double(0));
			agentPercent.setPercentAgentsChangeServingCell(new Double(0));
			agentPercent.setPercentAgentsNewActive(new Double(0));
			agentPercent.setPercentAgentsNewCallGenerated(new Double(0));
		} else {
			agentPercent.setPercentAgentsActivity(100*percentAgentsActivity/percentAgentsTotal.doubleValue());
			agentPercent.setPercentAgentsCallGenerated(100*percentAgentsCallGenerated/percentAgentsTotal.doubleValue());
			agentPercent.setPercentAgentsCallGeneratedMore(100*percentAgentsCallGeneratedMore/percentAgentsTotal.doubleValue());
			agentPercent.setPercentAgentsChangeServingCell(100*percentAgentsChangeServingCell/percentAgentsTotal.doubleValue());
			agentPercent.setPercentAgentsNewActive(100*percentAgentsNewActive/percentAgentsTotal.doubleValue());
			agentPercent.setPercentAgentsNewCallGenerated(100*percentAgentsNewCallGenerated/percentAgentsTotal.doubleValue());
		}
	}


	/**
	 * @return the agentPercent
	 */
	public AgentPercent getAgentPercent() {
		return agentPercent;
	}


	/**
	 * @param grxPercent the grxPercent to set
	 */
	public void setGrxPercent() {
		grxPercent = new GrxPercent();
		Long percentSamplesGood = new Long(0);
		Long percentSamplesTotal = new Long(0);
		for (GrxPercent item : grxPercents) {
			percentSamplesGood = percentSamplesGood + item.getNbSamplesGood();
			percentSamplesTotal = percentSamplesTotal + item.getNbSamplesTotal();
		}
		if (percentSamplesTotal==0){
			grxPercent.setPercentSamplesGood(new Double(0));
		} else {
			grxPercent.setPercentSamplesGood(100*percentSamplesGood/percentSamplesTotal.doubleValue());
		}
	}


	/**
	 * @param grxQualityPercent the grxQualityPercent to set
	 */
	public void setGrxQualityPercent() {
		grxQualityPercent = new GrxQualityPercent();
		Long percentSamplesGood = new Long(0);
		Long percentSamplesTotal = new Long(0);
		for (GrxQualityPercent item : grxQualityPercents) {
			percentSamplesGood = percentSamplesGood + item.getNbSamplesGood();
			percentSamplesTotal = percentSamplesTotal + item.getNbSamplesTotal();
		}
		if (percentSamplesTotal==0){
			grxQualityPercent.setPercentSamplesGood(new Double(0));	
		} else {
			grxQualityPercent.setPercentSamplesGood(100*percentSamplesGood/percentSamplesTotal.doubleValue());	
		}
	}

	
	/**
	 * @param grxPercent the grxPercent to set
	 */
	public void setCsrPercent() {
		csrPercent = new CsrPercent();
		Long percentCallSucceeded = new Long(0);
		Long percentCallTotal = new Long(0);
		for (CsrPercent item : csrPercents) {
			percentCallSucceeded = percentCallSucceeded + item.getNbCallSucceeded();
			percentCallTotal = percentCallTotal + item.getNbCallTotal();
		}
		
		if (percentCallTotal==0){
			csrPercent.setPercentCallSucceeded(new Double(0));			
		} else {
			csrPercent.setPercentCallSucceeded(100*percentCallSucceeded/percentCallTotal.doubleValue());
		}
	}

	/**
	 * @return the grxPercent
	 */
	public GrxPercent getGrxPercent() {
		return grxPercent;
	}

	/**
	 * @return the grxQualityPercent
	 */
	public GrxQualityPercent getGrxQualityPercent() {
		return grxQualityPercent;
	}

	/**
	 * @return the csrPercent
	 */
	public CsrPercent getCsrPercent() {
		return csrPercent;
	}

	/**
	 * @return the agentNoActivityNumber
	 */
	public Integer getAgentNoActivityNumber() {
		return agentNoActivityNumber;
	}

	/**
	 * @param agentNoActivityNumber the agentNoActivityNumber to set
	 */
	public void setAgentNoActivityNumber(Integer agentNoActivityNumber) {
		this.agentNoActivityNumber = agentNoActivityNumber;
	}

	/**
	 * @return the agentNoCallGeneratedNumber
	 */
	public Integer getAgentNoCallGeneratedNumber() {
		return agentNoCallGeneratedNumber;
	}

	/**
	 * @param agentNoCallGeneratedNumber the agentNoCallGeneratedNumber to set
	 */
	public void setAgentNoCallGeneratedNumber(Integer agentNoCallGeneratedNumber) {
		this.agentNoCallGeneratedNumber = agentNoCallGeneratedNumber;
	}

	/**
	 * @return the agentChangeServingCellNumber
	 */
	public Integer getAgentChangeServingCellNumber() {
		return agentChangeServingCellNumber;
	}

	/**
	 * @param agentChangeServingCellNumber the agentChangeServingCellNumber to set
	 */
	public void setAgentChangeServingCellNumber(Integer agentChangeServingCellNumber) {
		this.agentChangeServingCellNumber = agentChangeServingCellNumber;
	}

	/**
	 * @return the agentUseWeakRxNumber
	 */
	public Integer getAgentUseWeakRxNumber() {
		return agentUseWeakRxNumber;
	}

	/**
	 * @param agentUseWeakRxNumber the agentUseWeakRxNumber to set
	 */
	public void setAgentUseWeakRxNumber(Integer agentUseWeakRxNumber) {
		this.agentUseWeakRxNumber = agentUseWeakRxNumber;
	}

	/**
	 * @return the agentUseWeakRxQualityNumber
	 */
	public Integer getAgentUseWeakRxQualityNumber() {
		return agentUseWeakRxQualityNumber;
	}

	/**
	 * @param agentUseWeakRxQualityNumber the agentUseWeakRxQualityNumber to set
	 */
	public void setAgentUseWeakRxQualityNumber(Integer agentUseWeakRxQualityNumber) {
		this.agentUseWeakRxQualityNumber = agentUseWeakRxQualityNumber;
	}

	/**
	 * @return the agentLowCsrNumber
	 */
	public Integer getAgentLowCsrNumber() {
		return agentLowCsrNumber;
	}

	/**
	 * @param agentLowCsrNumber the agentLowCsrNumber to set
	 */
	public void setAgentLowCsrNumber(Integer agentLowCsrNumber) {
		this.agentLowCsrNumber = agentLowCsrNumber;
	}

	/**
	 * @return the agentAlerts
	 */
	public List<Agent> getAgentAlerts() {
		return agentAlerts;
	}

	/**
	 * @param agentAlerts the agentAlerts to set
	 */
	public void setAgentAlerts(List<Agent> agentAlerts) {
		this.agentAlerts = agentAlerts;
	}

	/**
	 * @return the msisdn
	 */
	public String getMsisdn() {
		return msisdn;
	}

	/**
	 * @param msisdn the msisdn to set
	 */
	public void setMsisdn(String msisdn) {
		this.msisdn = msisdn;
	}

	/**
	 * @return the imei
	 */
	public String getImei() {
		return imei;
	}

	/**
	 * @param imei the imei to set
	 */
	public void setImei(String imei) {
		this.imei = imei;
	}

	/**
	 * @return the customerId
	 */
	public String getCustomerId() {
		return customerId;
	}

	/**
	 * @param customerId the customerId to set
	 */
	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	/**
	 * @return the agents
	 */
	public List<Agent> getAgents() {
		return agents;
	}

	/**
	 * @param agents the agents to set
	 */
	public void setAgents(List<Agent> agents) {
		this.agents = agents;
	}

	/**
	 * @return the agent
	 */
	public Agent getAgent() {
		return agent;
	}

	/**
	 * @param agent the agent to set
	 */
	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	/**
	 * @return the cellId
	 */
	public Integer getCellId() {
		return cellId;
	}

	/**
	 * @param cellId the cellId to set
	 */
	public void setCellId(Integer cellId) {
		this.cellId = cellId;
	}


	/**
	 * @return the json
	 */
	public String getJson() {
		return json;
	}

	/**
	 * @param json the json to set
	 */
	public void setJson(String json) {
		this.json = json;
	}

	/**
	 * @return the countryId
	 */
	public Integer getCountryId() {
		return countryId;
	}

	/**
	 * @param countryId the countryId to set
	 */
	public void setCountryId(Integer countryId) {
		this.countryId = countryId;
	}

	/**
	 * @return the areaId
	 */
	public Integer getAreaId() {
		return areaId;
	}

	/**
	 * @param areaId the areaId to set
	 */
	public void setAreaId(Integer areaId) {
		this.areaId = areaId;
	}

	/**
	 * @return the provinceId
	 */
	public Integer getProvinceId() {
		return provinceId;
	}

	/**
	 * @param provinceId the provinceId to set
	 */
	public void setProvinceId(Integer provinceId) {
		this.provinceId = provinceId;
	}

	/**
	 * @return the onDate
	 */
	public String getOnDate() {
		return onDate;
	}

	/**
	 * @param onDate the onDate to set
	 */
	public void setOnDate(String onDate) {
		this.onDate = onDate;
	}

	/**
	 * @return the alertType
	 */
	public String getAlertType() {
		return typeAlert;
	}


	/**
	 * @return the typeAlert
	 */
	public String getTypeAlert() {
		return typeAlert;
	}

	/**
	 * @param typeAlert the typeAlert to set
	 */
	public void setTypeAlert(String typeAlert) {
		this.typeAlert = typeAlert;
	}

	/**
	 * @return the updateId
	 */
	public String getUpdateId() {
		return updateId;
	}

	/**
	 * @param updateId the updateId to set
	 */
	public void setUpdateId(String updateId) {
		this.updateId = updateId;
	}

	/**
	 * @return the page
	 */
	public Integer getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(Integer page) {
		this.page = page;
	}

	/**
	 * @return the total
	 */
	public Integer getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(Integer total) {
		this.total = total;
	}

	/**
	 * @return the start
	 */
	public Integer getStart() {
		return start;
	}

	/**
	 * @param start the start to set
	 */
	public void setStart(Integer start) {
		this.start = start;
	}

	/**
	 * @return the end
	 */
	public Integer getEnd() {
		return end;
	}

	/**
	 * @param end the end to set
	 */
	public void setEnd(Integer end) {
		this.end = end;
	}

	/**
	 * @return the pageNum
	 */
	public Integer getPageNum() {
		return pageNum;
	}

	/**
	 * @param pageNum the pageNum to set
	 */
	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	/**
	 * @return the data
	 */
	public String getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(String data) {
		this.data = data;
	}


	/**
	 * @return the fromDate
	 */
	public String getFromDate() {
		return fromDate;
	}


	/**
	 * @param fromDate the fromDate to set
	 */
	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}


	/**
	 * @return the toDate
	 */
	public String getToDate() {
		return toDate;
	}


	/**
	 * @param toDate the toDate to set
	 */
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}


	/**
	 * @return the niDatas
	 */
	public List<NiData> getNiDatas() {
		return niDatas;
	}


	/**
	 * @param niDatas the niDatas to set
	 */
	public void setNiDatas(List<NiData> niDatas) {
		this.niDatas = niDatas;
	}


	/**
	 * @return the countries
	 */
	public List<Country> getCountries() {
		return countries;
	}


	/**
	 * @param countries the countries to set
	 */
	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}


	/**
	 * @return the areas
	 */
	public List<Area> getAreas() {
		return areas;
	}


	/**
	 * @param areas the areas to set
	 */
	public void setAreas(List<Area> areas) {
		this.areas = areas;
	}


	/**
	 * @return the provinces
	 */
	public List<Province> getProvinces() {
		return provinces;
	}


	/**
	 * @param provinces the provinces to set
	 */
	public void setProvinces(List<Province> provinces) {
		this.provinces = provinces;
	}


	/**
	 * @return the parameters
	 */
	public List<Parameter> getParameters() {
		return parameters;
	}


	/**
	 * @param parameters the parameters to set
	 */
	public void setParameters(List<Parameter> parameters) {
		this.parameters = parameters;
	}


	/**
	 * @param agentPercents the agentPercents to set
	 */
	public void setAgentPercents(List<AgentPercent> agentPercents) {
		this.agentPercents = agentPercents;
	}


	/**
	 * @param grxPercents the grxPercents to set
	 */
	public void setGrxPercents(List<GrxPercent> grxPercents) {
		this.grxPercents = grxPercents;
	}


	/**
	 * @param grxQualityPercents the grxQualityPercents to set
	 */
	public void setGrxQualityPercents(List<GrxQualityPercent> grxQualityPercents) {
		this.grxQualityPercents = grxQualityPercents;
	}


	/**
	 * @param csrPercents the csrPercents to set
	 */
	public void setCsrPercents(List<CsrPercent> csrPercents) {
		this.csrPercents = csrPercents;
	}


	/**
	 * @return the agentPercents
	 */
	public List<AgentPercent> getAgentPercents() {
		return agentPercents;
	}


	/**
	 * @return the grxPercents
	 */
	public List<GrxPercent> getGrxPercents() {
		return grxPercents;
	}


	/**
	 * @return the grxQualityPercents
	 */
	public List<GrxQualityPercent> getGrxQualityPercents() {
		return grxQualityPercents;
	}


	/**
	 * @return the csrPercents
	 */
	public List<CsrPercent> getCsrPercents() {
		return csrPercents;
	}


	/**
	 * @return the toolTip
	 */
	public String getToolTip() {
		return toolTip;
	}


	/**
	 * @param toolTip the toolTip to set
	 */
	public void setToolTip(String toolTip) {
		this.toolTip = toolTip;
	}
	
}
